package com.qiguliuxing.dts.service.base;

import com.github.pagehelper.PageHelper;
import com.qiguliuxing.dts.db.dao.DtsBankSupportMapper;
import com.qiguliuxing.dts.db.domain.DtsBankSupport;
import com.qiguliuxing.dts.db.domain.DtsBankSupportExample;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.util.List;

@Service
public class DtsBankSupportService {
	@Resource
	private DtsBankSupportMapper dtsBankSupportMapper;

	public List<DtsBankSupport> queryAll(){
		return dtsBankSupportMapper.selectByExample(new DtsBankSupportExample());
	}

    public List<DtsBankSupport> querySelective(String name, String code, Integer page, Integer limit, String sort, String order) {
		DtsBankSupportExample example = new DtsBankSupportExample();
		DtsBankSupportExample.Criteria criteria = example.createCriteria();

		if (!StringUtils.isEmpty(name)) {
			criteria.andBankNameLike("%" + name + "%");
		}
		if (!StringUtils.isEmpty(code)) {
			criteria.andBankCodeLike("%" + code + "%");
		}

		if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
			example.setOrderByClause(sort + " " + order);
		}

		PageHelper.startPage(page, limit);
		return dtsBankSupportMapper.selectByExample(example);
    }

	public void add(DtsBankSupport bank) {
		dtsBankSupportMapper.insertSelective(bank);
	}

	public int updateById(DtsBankSupport bank) {
		return dtsBankSupportMapper.updateByPrimaryKeySelective(bank);
	}

	public void deleteById(Integer id) {
		dtsBankSupportMapper.deleteByPrimaryKey(id);
	}
}
